package com.baishui.core.type.classreading;


import com.baishui.core.annotation.AnnotationAttributes;
import org.springframework.asm.AnnotationVisitor;
import org.springframework.asm.SpringAsmInfo;

import java.util.Map;

/**
 *  注解中属性的 visitor
 */
final class AnnotationAttributesReadingVisitor extends AnnotationVisitor {

	/**
	 * 注解的全限列名
	 */
	private final String annotationType;

	/**
	 * <注解，注解中属性 Map<name,value> >
	 */
	private final Map<String, AnnotationAttributes> attributesMap;

	AnnotationAttributes attributes = new AnnotationAttributes();

	public AnnotationAttributesReadingVisitor(
			String annotationType, Map<String, AnnotationAttributes> attributesMap) {
		super(SpringAsmInfo.ASM_VERSION);
		
		this.annotationType = annotationType;
		this.attributesMap = attributesMap;
	}

	/**
	 * 进行保存
	 */
	@Override
	public final void visitEnd(){
		this.attributesMap.put(this.annotationType, this.attributes);
	}

	/**
	 * 先进行注解属性的对象的保存
	 * @param attributeName 注解属性的名称
	 * @param attributeValue 注解属性名称所对应的value
	 */
	@Override
	public void visit(String attributeName, Object attributeValue) {
		this.attributes.put(attributeName, attributeValue);
	}


}
